<template>
    <div class="course-album"  @scroll="handleScroll($event)">
        <div class="top" v-if="!turnTop">
            <div class="arrow-left" @click="$router.go(-1)">
                <img src="../assets/images/album_main_back.png" alt="" />
            </div>
        <div class="list-right">
            <img
              class="wechat"
              src="../assets/images/album_main_wechat.png"
              alt=""
            />
            <img src="../assets/images/album_main_pyq.png" alt="" />
            <img class="dots" src="../assets/images/album_main_more.png" alt="" />
        </div>
        </div>
        <div class="top" style="backgroundColor:#fff" v-if="turnTop">
            <div class="arrow-left" @click="$router.go(-1)">
                <img src="../assets/images/back_b_icon.png" alt="" />
            </div>
        <div class="list-right">
            <img
              class="wechat"
              src="../assets/images/tittle_share_wechat.png"
              alt=""
            />
            <img src="../assets/images/tittle_share_pyq.png" alt="" />
            <img class="dots" src="../assets/images/black_more.png" alt="" />
        </div>
        </div>
        <div 
        class="coursebg"
        v-if="ablumdetail"
        :style="{'background-image': 'url(https://pic.ecook.cn/web/'+ablumdetail.vimg+'.jpg!wl280)',}"
        >
        </div>
        <div class="ablumCon" v-if="ablumdetail">
            <div class="ablumTop">
                <div class="upImg">
                    <img src="../assets/images/向上箭头.png" alt="">
                </div>
                <div class="ablumname">{{ablumdetail.title}}</div>
                <div class="abluminfo">
                    <div class="ablumNum">共{{ablumdetail.teachNum}}节课程</div>
                    <div class="tags" v-if="tags">
                        <span v-for="(item,index) in tags" :key="index">{{item}}</span>
                    </div>
                </div>
            </div>
            <div class="ablumRecommend">
                <div class="RecomTitle">专辑简介</div>
                <div class="description" v-html="description"></div>
            </div>
            <div class="ablumlist">
                <div class="listtitle">专辑目录</div>
                <div class="ablumItem" v-for="item in teachs" :key="item.id" @click.stop="godetail(item.id)">
                    <div class="ablumImg" :style="{'background-image': 'url(https://pic.ecook.cn/web/'+item.himg+'.jpg!wl280)',}"></div>
                    <div class="ablumtitle">{{item.title}}</div>
                    <div class="ablumAuthor">
                        <div class="authorImg" @click.stop="author(item.teacher.id)">
                            <img :src="'https://pic.ecook.cn/web/'+item.teacher.imageid+'.jpg!s1'" alt="">
                        </div>
                        <div class="nickname" @click.stop="author(item.teacher.id)">{{item.teacher.nickname}}</div>
                    </div>
                </div>
            </div>
            <div class="bottom" v-show="showbottom">
                <div class="bottomleft" @click="buy">
                  <div class="toptext">购买专辑 ¥{{price}}.0</div>
                  <div class="bottomtext">{{coinPrice}}厨币可兑换</div>
                </div>
                <div class="bottomright">
                  <div class="logo">
                    <img src="../assets/images/me_vip_icon_yellow.png" alt="">
                  </div>
                  <div class="text">会员免费学</div>
                </div>
            </div>
        </div>
    </div>
</template>

<script>
import {getOnlineTeachAlbumDetailsData,getCheckuserpayData} from "../api/class"
export default {
    data() {
        return {
            ablumdetail:null,//详情数据
            tags:null,//tags
            description:null,//描述
            teachs:null,//专辑目录
            coinPrice:null,//厨币
            price:null,//价格
            showbottom:false,
            turnTop:false,
            scorlly:0,
        };
    },

    methods: {
        //获取数据
        getOnlineTeachAlbumDetailsFun(id){
            getOnlineTeachAlbumDetailsData({id}).then(data=>{
                console.log(data);
                if (data.data) {
                    this.ablumdetail = data.data
                    if (data.data.tags.length) {
                        let temptags = data.data.tags[0].split(" ")
                        this.tags = temptags.filter(item=>item!='')
                    }
                    this.description = data.data.description
                    this.teachs = data.data.teachs
                }
            })
        },
        //价格
        getCheckuserpayFun(id){
            getCheckuserpayData({albumId:id}).then(data=>{
                console.log(data);
                if (data.data) {
                    this.coinPrice = data.data.coinPrice
                    this.price = data.data.price
                }
            })
        },
        godetail(id){
            this.$router.push({path:'/course',query:{id}})
        },
        author(id){
            this.$router.push({path:'/author',query:{id}})
        },
        //实时滚动改变状态
        handleScroll(e){
            // console.log(e.target.scrollTop);
            if (e.target.scrollTop==0) {
                this.showbottom = false
            }else if(e.target.scrollTop>=190){
                this.showbottom = true
            }
            if (e.target.scrollTop<=400) {
                this.turnTop = false
            }else{
                this.turnTop = true
            }
        },
        //购买课程
        buy(){
          let daylist = JSON.parse(window.localStorage.getItem("signlist"))
          daylist=daylist==null?[]:daylist
          let cookCoin = 0
          for (let i = 0; i < daylist.length; i++) {
            cookCoin +=30
          }
          if (this.coinPrice>=cookCoin) {
            this.$toast("厨币不足！")
          }else{
            this.$toast("购买成功！")
          }
        },
    },
    created() {
        this.getOnlineTeachAlbumDetailsFun(this.$route.query.id)
        this.getCheckuserpayFun(this.$route.query.id)
    },
};
</script>

<style lang="less" scoped>
.course-album{
    width: 100%;
    height: 100%;
    overflow-y: scroll;

    .top {
    position: fixed;
    left: 0;
    right: 0;
    z-index: 99;
    height: 35px;
    padding: 5px;
    display: flex;
    justify-content: space-between;
    box-sizing: border-box;
    // background-image: linear-gradient(#9d9fa3, transparent);

    .arrow-left {
      width: 15%;
      display: flex;
      align-items: center;

      & > img {
        width: 10px;
        height: 18px;
        display: inline-block;
        padding-left: 5px;
      }
    }

    .list-right {
      width: 50%;
      display: flex;
      justify-content: flex-end;
      align-items: center;

      & > img {
        padding: 0 15px;
        width: 20px;
        height: 20px;
        display: block;
      }

      .wechat {
        width: 23px;
      }

      .dots {
        height: 5px;
      }
    }
    }
    // 背景图
    .coursebg{
      width: 100%;
      height: 380px;
      background-repeat: no-repeat;
      background-size: cover;
    }
    .ablumCon{
        background-color: #fff;
        position: relative;
        top: -5px;
        border-top-right-radius: 8px;
        border-top-left-radius: 8px;
        margin-bottom: 100px;
        
        .ablumTop{
            margin-bottom: 30px;
            .upImg{
                width: 100%;
                text-align: center;
                padding: 10px 0;
                &>img{
                    width: 35px;
                    height: 20px;
                }
            }
            .ablumname{
                padding: 0 18px;
                font-size: 18px;
                font-weight: bold;
                margin-bottom: 20px;
                line-height: 22px;
                letter-spacing: 0.5px;
            }
            .abluminfo{
                padding: 0 18px;
                display: flex;
                align-items: center;

                .ablumNum{
                    margin-right: 5px;
                    font-size: 14px;
                    letter-spacing: 0.5px;
                }
                .tags{
                    flex: 1;
                    text-align: right;
                    font-size: 13px;

                    &>span{
                        padding:2px 8px;
                        background-color: #efefef;
                        margin: 0 5px;
                        border-radius: 6px;
                        color: #989898;
                    }
                }
            }
        }
        .ablumRecommend{
            margin-bottom: 30px;
            .RecomTitle{
                padding: 10px 15px 20px 15px;
                font-weight: 700;
            }
            .description{
                padding: 0 18px;
                line-height: 22px;
                font-size: 15px;
                letter-spacing: 0.5px;
                white-space: pre-wrap;
            }
        }
        .ablumlist{
            margin-bottom: 30px;
            .listtitle{
                padding: 10px 15px 20px 15px;
                font-weight: 700;
            }
            .ablumItem{
                margin-top: 20px;
                padding: 0 15px;
                background-image: linear-gradient(#fefefe,#ebebeb);

                .ablumImg{
                    width: 100%;
                    height: 180px;
                    border-radius: 8px;
                    background-repeat: no-repeat;
                    background-position: center;
                    background-size: cover;
                }
                .ablumtitle{
                    padding: 15px 0;
                    font-weight: 700;
                }
                .ablumAuthor{
                    padding-bottom: 15px;
                    display: flex;
                    align-items: center;
                    .authorImg{
                        width: 25px;
                        height: 25px;
                        border-radius: 50%;
                        overflow: hidden;
                        margin-right: 8px;
                    }
                    .nickname{
                        font-size: 14px;
                        letter-spacing: 0.5px;
                        color: #5c5c5c;
                    }
                }
            }
        }
    }
    .bottom{
       position: fixed;
       bottom: 0;
       left: 0;
       right: 0;
       z-index: 2;
       background-color: #fff;
       height: 60px;
       display: flex;
       justify-content: space-between;
       align-items: center;

       .bottomleft{
      width: 162px;
      height: 46px;
      margin: 0 7.5px 0 15px;
      text-align: center;
      border-radius: 6px;
      background-color: #fefaef;
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;

      .toptext{
        color: #f0b65f;
        font-weight: 700;
        letter-spacing: 0.5px;
        margin-bottom: 8px;
        font-size: 15px;
      }
      .bottomtext{
        font-size: 12px;
        color: #eeb368;
      }
       }
       .bottomright{
      width: 162px;
      height: 46px;
      margin: 0 15px 0 7.5px;
      text-align: center;
      border-radius: 6px;
      background-image: linear-gradient(90deg,#f3d076,#b68d1d);
      display: flex;
      align-items: center;
      justify-content: center;

      .logo{
        width: 20px;
        display: inline-block;
        margin-right: 8px;
      }
      .text{
        display: inline-block;
        color: #fff;
        font-size: 15px;
        font-weight: 700;
        letter-spacing: 0.5px;
      }
       }
    }
}
</style>